package com.zhijian.medical.controller;

import com.zhijian.medical.annotation.Response;
import com.zhijian.medical.entity.vo.request.QcSearchVo;
import com.zhijian.medical.entity.vo.request.QcStatisticsSearchVo;
import com.zhijian.medical.entity.vo.request.QcUpdateVo;
import com.zhijian.medical.entity.vo.response.QcStatistics2Vo;
import com.zhijian.medical.entity.vo.response.QcStatisticsVo;
import com.zhijian.medical.entity.vo.response.QcVo;
import com.zhijian.medical.service.QcService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 质控 控制层
 *
 * @author HCG
 * @version 1.0
 * @date 2022-10-19 13:36:43
 */
@Slf4j
@Controller
@Api(tags = "质控")
public class QcController {

    @Autowired
    private QcService service;

    /**
     * 列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/qc/list")
    @ApiOperation("列表查询")
    public List<QcVo> selectByCondition(@RequestBody(required = false) QcSearchVo param) {
        if (param == null)
            param = QcSearchVo.builder().build();
        return service.render(param);
    }

    /**
     * 根据父数据名称获取子数据列表
     *
     * @param parentName
     * @return
     */
    @Response
    @GetMapping("/qc/children/list")
    @ApiOperation("根据父数据名称获取子数据列表")
    public List<QcVo> selectChildrenByParentName(@RequestParam(value = "parentName") String parentName) {
        return service.selectChildrenByParentName(parentName);
    }

    /**
     * 保存全部
     *
     * @param qcUpdateList
     * @return
     */
    @Response
    @PutMapping("/qc")
    @ApiOperation("保存全部")
    public boolean updateAll(@RequestBody List<QcUpdateVo> qcUpdateList) {
        return service.updateAll(qcUpdateList);
    }

    /**
     * 数据统计
     *
     * @param qcStatisticsSearchVo
     * @return
     */
    @Response
    @PostMapping("/qc/statistics")
    @ApiOperation("数据统计")
    public List<QcStatisticsVo> statistics(@RequestBody QcStatisticsSearchVo qcStatisticsSearchVo) {
        return service.statistics(qcStatisticsSearchVo);
    }

    /**
     * 数据统计
     *
     * @param qcStatisticsSearchVo
     * @return
     */
    @Response
    @PostMapping("/qc/statistics2")
    @ApiOperation("数据统计")
    public List<QcStatistics2Vo> statistics2(@RequestBody QcStatisticsSearchVo qcStatisticsSearchVo) {
        return service.statistics2(qcStatisticsSearchVo);
    }

    /**
     * 数据统计导出EXCEL
     *
     * @param qcStatisticsSearchVo
     * @return
     */
    @Response
    @PostMapping("/qc/export")
    @ApiOperation("数据统计导出EXCEL")
    public void export(@RequestBody QcStatisticsSearchVo qcStatisticsSearchVo, HttpServletResponse response) {
        service.export(qcStatisticsSearchVo, response);
    }

}